<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <canvas id="canvas" height="600" width="700"></canvas>
<script>
    const canvas = document.getElementById('canvas')
    const ctx = canvas.getContext('2d')
    // 居中对齐文本：
    ctx.beginPath()
    ctx.font = '40px Verdana'
    ctx.textAlign = 'center'
    ctx.fillText('Hello Canvas!', 350, 300, 400)

    // 两条相互垂直的辅助线，两条线的交点为文本绘制的起始点：
    ctx.beginPath()
    ctx.moveTo(350, 0)
    ctx.lineTo(350, 600)
    ctx.setLineDash([10])
    ctx.globalAlpha = 0.5
    ctx.stroke()
    ctx.beginPath()
    ctx.moveTo(0, 300)
    ctx.lineTo(700, 300)
    ctx.stroke()
</script>
</body>

</html>